home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / j / amiga / j41_amig.zoo / changes / io.c next >
C/C++ Source or Header  |  1992-03-25  |  4KB  |  134 lines

  1. /* ----------------------------------------------------------------------- */
  2. /* J-Source Version 4.1 - COPYRIGHT 1992 Iverson Software Inc.             */
  3. /* 33 Major Street, Toronto, Ontario, Canada, M5S 2K9, (416) 925 6096      */
  4. /*                                                                         */
  5. /* J-Source is provided "as is" without warranty of any kind.              */
  6. /*                                                                         */
  7. /* J-Source Version 4.1 license agreement:  You may use, copy, and         */
  8. /* modify the source.  You have a non-exclusive, royalty-free right        */
  9. /* to redistribute source and executable files.                            */
  10. /* ----------------------------------------------------------------------- */
  11.  
  12. /*                                                                         */
  13. /* Input/Output                                                            */
  14.  
  15. #include "j.h"
  16. #include "io.h"
  17.  
  18. static C          inbuf[2+NINPUT];
  19.  
  20. F1(joff){if(outfile&&outfile!=stdout)fclose(outfile); sesmexit(); exit(0);}
  21.  
  22. void jouts(s)C*s;{if(outfile)fputc(COUT,outfile); jputs(s);}
  23.  
  24.  
  25. /* --------------------- Special Session Manager ------------------------- */
  26.  
  27. #if (!LINKJ && SYS & SYS_SESM)
  28.  
  29. C breaker(){if(sesm)jstkiav(); R!jerr;}
  30.  
  31. A jgets(){C c,*s=inbuf;I k=0,n;
  32.  if(infile==stdin){if(sesm)jsti(NINPUT,s); else RZ(fgets(s,NINPUT,stdin));}
  33.  else{do RZ(fgets(s,NINPUT,infile))while(COUT==*s); k=strspn(s," ");}
  34.  n=strlen(s); if(c=*(s+n-1),CLF==c||CCR==c){--n; *(s+n)=0;}
  35.  if(infile!=stdin){jputs(k+s); jputc(CNL);}
  36.  else if(outfile){fputs(k+s,outfile); fputc(CNL,outfile);}
  37.  if(CCTRLD==*(s+n-1))joff();
  38.  R str(n,s);
  39. }
  40.  
  41. void jputc(c)C c;{
  42.  if(tostdout){if(sesm)jsto(MTYOUT,1,&c); else fputc(c,stdout);}
  43.  if(outfile)fputc(c,outfile);
  44. }
  45.  
  46. void jputs(s)C*s;{
  47.  if(tostdout){if(sesm)jsto(MTYOUT,(int)strlen(s),s); else fputs(s,stdout);}
  48.  if(outfile)fputs(s,outfile);
  49. }
  50.  
  51. void prompt(s)C*s;{
  52.  if(tostdout){if(sesm)jsto(MTYOIN,(int)strlen(s),s); else fputs(s,stdout);}
  53.  if(outfile)fputs(s,outfile);
  54. }
  55.  
  56. void sesmexit(){if(sesm)jststop();}
  57.  
  58. C sesminit(){
  59.  if(sesm){A t;I j,mask=0xfffffff0L;struct{I*vlog;S nlog;I*vinb;S ninb;I*vfkd;S nfkd;}in;
  60. #if (SYS & SYS_PCAT)
  61.   /* The 15+ and &0xfffffff0 are because addresses must be segment aligned */
  62.   GA(t,CHAR,15+NLOG,1,0); j=(I)(15+(C*)AV(t)); j&=mask; in.vlog=(I*)j; in.nlog=NLOG;
  63.   GA(t,CHAR,15+NINB,1,0); j=(I)(15+(C*)AV(t)); j&=mask; in.vinb=(I*)j; in.ninb=NINB;
  64.   GA(t,CHAR,15+NFKD,1,0); j=(I)(15+(C*)AV(t)); j&=mask; in.vfkd=(I*)j; in.nfkd=NFKD;
  65. #endif
  66.   jstinit((Ptr)&in);
  67.  }
  68.  R 1;
  69. }
  70.  
  71. C*wr(n,v)I n;C*v;{I k=0,m;
  72.  if(tostdout){
  73.   if(sesm)while(n>k&&!jerr){m=MIN(3000,n-k); jsto(MTYOUT,(int)m,v+k); k+=m;}
  74.   else    while(n>k&&!jerr)k+=fwrite(v+k,sizeof(C),(size_t)(n-k),stdout);
  75.  }
  76.  if(outfile){
  77.   fputc(COUT,outfile);
  78.   k=0;    while(n>k&&!jerr)k+=fwrite(v+k,sizeof(C),(size_t)(n-k),outfile);
  79.  }
  80.  jputc(CNL); R v+n;
  81. }
  82.  
  83.  
  84. /* --------------------- Others (No Session Manager) --------------------- */
  85.  
  86. #else
  87.  
  88. C breaker(){R!jerr;}
  89.  
  90. A jgets(){C*s=inbuf;I k=0,n;
  91.  if(infile==stdin)RZ(fgets(s,NINPUT,stdin))
  92.  else{do RZ(fgets(s,NINPUT,infile))while(COUT==*s); k=strspn(s," ");}
  93.  n=strlen(s); if(CNL==*(s+n-1)){--n; *(s+n)=0;}
  94.  if(infile!=stdin){jputs(k+s); jputc(CNL);}
  95.  else if(outfile){fputs(k+s,outfile); fputc(CNL,outfile);}
  96.  if(CCTRLD==*(s+n-1))joff();
  97.  R str(n,s);
  98. }
  99.  
  100. #if (SYS & SYS_AMIGA)
  101. void jputc(c)C c;{if(tostdout){fputc(c,stdout); fflush(stdout);}
  102.   if(outfile)fputc(c,outfile);
  103. }
  104.  
  105. void jputs(s)C*s;{if(tostdout){fputs(s,stdout); fflush(stdout);}
  106.   if(outfile)fputs(s,outfile);
  107. }
  108.  
  109. #else
  110.  
  111. void jputc(c)C c;{if(tostdout)fputc(c,stdout); if(outfile)fputc(c,outfile);
  112.  
  113. void jputs(s)C*s;{if(tostdout)fputs(s,stdout); if(outfile)fputs(s,outfile);}
  114. #endif
  115.  
  116.  
  117. void prompt(s)C*s;{jputs(s);}
  118.  
  119. void sesmexit(){}
  120.  
  121. C sesminit(){R 1;}
  122.  
  123. C*wr(n,v)I n;C*v;{I k=0;
  124.  if(tostdout)while(n>k&&!jerr)k+=fwrite(v+k,sizeof(C),(size_t)(n-k),stdout);
  125.  if(outfile){
  126.   fputc(COUT,outfile);
  127.   k=0;       while(n>k&&!jerr)k+=fwrite(v+k,sizeof(C),(size_t)(n-k),outfile);
  128.  }
  129.  jputc(CNL); R v+n;
  130. }
  131.  
  132. #endif
  133.  
  134.